<template>
  <div>
    <a-form :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
      <a-form-item>
        <template slot="label">
          <ZgCheckbox v-model="obj.isPwdCk">密码</ZgCheckbox>
        </template>
        <div class="flx-s">
          <a-input-password class="w160 mr10" v-model="obj.pwd"></a-input-password>
          <ZgButton @click="setDefaultPwd" size="small" type="link" icon="pencil">设为默认值</ZgButton>
        </div>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <ZgCheckbox v-model="obj.isSexCk">性别</ZgCheckbox>
        </template>
        <ZgDictionary :width="160" code="sex" v-model="obj.sex"></ZgDictionary>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <ZgCheckbox v-model="obj.isEduLevelCk">学历</ZgCheckbox>
        </template>
        <ZgDictionary :width="160" code="eduLevel" v-model="obj.eduLevel"></ZgDictionary>
      </a-form-item>
      <a-form-item>
        <template slot="label">
          <ZgCheckbox v-model="obj.isOpenCk">状态</ZgCheckbox>
        </template>
        <ZgSwitch :width="100" v-model="obj.isOpen"></ZgSwitch>
      </a-form-item>
    </a-form>
  </div>
</template>
<script>
export default {
  props: {
    ids: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      obj: {
        isPwdCk: false,
        isSexCk: false,
        isEduLevelCk: false,
        isOpenCk: false,
        pwd: '',
        sex: '',
        eduLevel: '',
        isOpen: true
      }
    }
  },
  methods: {
    setDefaultPwd () {
      this.obj.pwd = this.genDefaultPwd()
    },
    save () {
      if (this.obj.isPwdCk === false &&
        this.obj.isSexCk === false &&
        this.obj.isEduLevelCk === false &&
        this.obj.isOpenCk === false) {
        return this.$result.error('请选择要设置的属性')
      }
      if (this.obj.isPwdCk && this.obj.pwd.length === 0) {
        return this.$result.error('请设置密码')
      }
      if (this.obj.isSexCk && this.obj.sex.length === 0) {
        return this.$result.error('请设置性别')
      }
      if (this.obj.isEduLevelCk && this.obj.eduLevel.length === 0) {
        return this.$result.error('请设置学历')
      }

      return this.$result.ok(
        Object.assign(
          {},
          this.obj,
          {
            ids: this.ids,
            pwd: this.genPwd(this.obj.pwd)
          }
        )
      )
    }
  }
}
</script>

<style lang="scss" scoped>
.ant-form-item{
  margin-bottom:5px;
}
</style>
